import string
string = "just a string :-) ololol :-) :-D *TT*"
smile = [":-)", ":-D", "*TT*"]
image = ["img1",
        "img2", "img3"]
print "String is: " + string
for s in smile:
    if s in string:
        first = string.find(s)
        last = string.rfind(s)
        if last != first:
            i = 0
            while string.count(s) != 0:
                cnt = smile.index(s)
                pos = string.find(s, i)
                string = string.replace(s, image[cnt], 1)
            #while string.find(s, i) != -1:
            #   cnt = smile.index(s)
            #    string = string.replace(s, image[cnt])
            i = i+1
        else:
            pos = string.find(s)
            cnt = smile.index(s)
            string = string.replace(s, image[cnt])
print "Parsed string: " + string
